home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Mac / Modules / snd / Sndmodule.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-12  |  20.8 KB  |  804 lines  |  [TEXT/CWIE]

  1.  
  2. /* =========================== Module Snd =========================== */
  3.  
  4. #include "Python.h"
  5.  
  6.  
  7.  
  8. #define SystemSevenOrLater 1
  9.  
  10. #include "macglue.h"
  11. #include <Memory.h>
  12. #include <Dialogs.h>
  13. #include <Menus.h>
  14. #include <Controls.h>
  15.  
  16. extern PyObject *ResObj_New(Handle);
  17. extern int ResObj_Convert(PyObject *, Handle *);
  18. extern PyObject *OptResObj_New(Handle);
  19. extern int OptResObj_Convert(PyObject *, Handle *);
  20.  
  21. extern PyObject *WinObj_New(WindowPtr);
  22. extern int WinObj_Convert(PyObject *, WindowPtr *);
  23. extern PyTypeObject Window_Type;
  24. #define WinObj_Check(x) ((x)->ob_type == &Window_Type)
  25.  
  26. extern PyObject *DlgObj_New(DialogPtr);
  27. extern int DlgObj_Convert(PyObject *, DialogPtr *);
  28. extern PyTypeObject Dialog_Type;
  29. #define DlgObj_Check(x) ((x)->ob_type == &Dialog_Type)
  30.  
  31. extern PyObject *MenuObj_New(MenuHandle);
  32. extern int MenuObj_Convert(PyObject *, MenuHandle *);
  33.  
  34. extern PyObject *CtlObj_New(ControlHandle);
  35. extern int CtlObj_Convert(PyObject *, ControlHandle *);
  36.  
  37. extern PyObject *GrafObj_New(GrafPtr);
  38. extern int GrafObj_Convert(PyObject *, GrafPtr *);
  39.  
  40. extern PyObject *BMObj_New(BitMapPtr);
  41. extern int BMObj_Convert(PyObject *, BitMapPtr *);
  42.  
  43. extern PyObject *WinObj_WhichWindow(WindowPtr);
  44.  
  45. #include <Sound.h>
  46.  
  47. #ifndef HAVE_UNIVERSAL_HEADERS
  48. #define SndCallBackUPP ProcPtr
  49. #define NewSndCallBackProc(x) ((SndCallBackProcPtr)(x))
  50. #define SndListHandle Handle
  51. #endif
  52.  
  53. #include <OSUtils.h> /* for Set(Current)A5 */
  54.  
  55. /* Create a SndCommand object (an (int, int, int) tuple) */
  56. static PyObject *
  57. SndCmd_New(SndCommand *pc)
  58. {
  59.     return Py_BuildValue("hhl", pc->cmd, pc->param1, pc->param2);
  60. }
  61.  
  62. /* Convert a SndCommand argument */
  63. static int
  64. SndCmd_Convert(PyObject *v, SndCommand *pc)
  65. {
  66.     int len;
  67.     pc->param1 = 0;
  68.     pc->param2 = 0;
  69.     if (PyTuple_Check(v)) {
  70.         if (PyArg_ParseTuple(v, "h|hl", &pc->cmd, &pc->param1, &pc->param2))
  71.             return 1;
  72.         PyErr_Clear();
  73.         return PyArg_ParseTuple(v, "hhs#", &pc->cmd, &pc->param1, &pc->param2, &len);
  74.     }
  75.     return PyArg_Parse(v, "h", &pc->cmd);
  76. }
  77.  
  78. static pascal void SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd); /* Forward */
  79.  
  80. static PyObject *Snd_Error;
  81.  
  82. /* --------------------- Object type SndChannel --------------------- */
  83.  
  84. staticforward PyTypeObject SndChannel_Type;
  85.  
  86. #define SndCh_Check(x) ((x)->ob_type == &SndChannel_Type)
  87.  
  88. typedef struct SndChannelObject {
  89.     PyObject_HEAD
  90.     SndChannelPtr ob_itself;
  91.     /* Members used to implement callbacks: */
  92.     PyObject *ob_callback;
  93.     long ob_A5;
  94.     SndCommand ob_cmd;
  95. } SndChannelObject;
  96.  
  97. static PyObject *SndCh_New(itself)
  98.     SndChannelPtr itself;
  99. {
  100.     SndChannelObject *it;
  101.     it = PyObject_NEW(SndChannelObject, &SndChannel_Type);
  102.     if (it == NULL) return NULL;
  103.     it->ob_itself = itself;
  104.     it->ob_callback = NULL;
  105.     it->ob_A5 = SetCurrentA5();
  106.     return (PyObject *)it;
  107. }
  108. static SndCh_Convert(v, p_itself)
  109.     PyObject *v;
  110.     SndChannelPtr *p_itself;
  111. {
  112.     if (!SndCh_Check(v))
  113.     {
  114.         PyErr_SetString(PyExc_TypeError, "SndChannel required");
  115.         return 0;
  116.     }
  117.     *p_itself = ((SndChannelObject *)v)->ob_itself;
  118.     return 1;
  119. }
  120.  
  121. static void SndCh_dealloc(self)
  122.     SndChannelObject *self;
  123. {
  124.     SndDisposeChannel(self->ob_itself, 1);
  125.     Py_XDECREF(self->ob_callback);
  126.     PyMem_DEL(self);
  127. }
  128.  
  129. static PyObject *SndCh_SndDoCommand(_self, _args)
  130.     SndChannelObject *_self;
  131.     PyObject *_args;
  132. {
  133.     PyObject *_res = NULL;
  134.     OSErr _err;
  135.     SndCommand cmd;
  136.     Boolean noWait;
  137.     if (!PyArg_ParseTuple(_args, "O&b",
  138.                           SndCmd_Convert, &cmd,
  139.                           &noWait))
  140.         return NULL;
  141.     _err = SndDoCommand(_self->ob_itself,
  142.                         &cmd,
  143.                         noWait);
  144.     if (_err != noErr) return PyMac_Error(_err);
  145.     Py_INCREF(Py_None);
  146.     _res = Py_None;
  147.     return _res;
  148. }
  149.  
  150. static PyObject *SndCh_SndDoImmediate(_self, _args)
  151.     SndChannelObject *_self;
  152.     PyObject *_args;
  153. {
  154.     PyObject *_res = NULL;
  155.     OSErr _err;
  156.     SndCommand cmd;
  157.     if (!PyArg_ParseTuple(_args, "O&",
  158.                           SndCmd_Convert, &cmd))
  159.         return NULL;
  160.     _err = SndDoImmediate(_self->ob_itself,
  161.                           &cmd);
  162.     if (_err != noErr) return PyMac_Error(_err);
  163.     Py_INCREF(Py_None);
  164.     _res = Py_None;
  165.     return _res;
  166. }
  167.  
  168. static PyObject *SndCh_SndPlay(_self, _args)
  169.     SndChannelObject *_self;
  170.     PyObject *_args;
  171. {
  172.     PyObject *_res = NULL;
  173.     OSErr _err;
  174.     SndListHandle sndHdl;
  175.     Boolean async;
  176.     if (!PyArg_ParseTuple(_args, "O&b",
  177.                           ResObj_Convert, &sndHdl,
  178.                           &async))
  179.         return NULL;
  180.     _err = SndPlay(_self->ob_itself,
  181.                    sndHdl,
  182.                    async);
  183.     if (_err != noErr) return PyMac_Error(_err);
  184.     Py_INCREF(Py_None);
  185.     _res = Py_None;
  186.     return _res;
  187. }
  188.  
  189. static PyObject *SndCh_SndStartFilePlay(_self, _args)
  190.     SndChannelObject *_self;
  191.     PyObject *_args;
  192. {
  193.     PyObject *_res = NULL;
  194.     OSErr _err;
  195.     short fRefNum;
  196.     short resNum;
  197.     long bufferSize;
  198.     Boolean async;
  199.     if (!PyArg_ParseTuple(_args, "hhlb",
  200.                           &fRefNum,
  201.                           &resNum,
  202.                           &bufferSize,
  203.                           &async))
  204.         return NULL;
  205.     _err = SndStartFilePlay(_self->ob_itself,
  206.                             fRefNum,
  207.                             resNum,
  208.                             bufferSize,
  209.                             0,
  210.                             0,
  211.                             0,
  212.                             async);
  213.     if (_err != noErr) return PyMac_Error(_err);
  214.     Py_INCREF(Py_None);
  215.     _res = Py_None;
  216.     return _res;
  217. }
  218.  
  219. static PyObject *SndCh_SndPauseFilePlay(_self, _args)
  220.     SndChannelObject *_self;
  221.     PyObject *_args;
  222. {
  223.     PyObject *_res = NULL;
  224.     OSErr _err;
  225.     if (!PyArg_ParseTuple(_args, ""))
  226.         return NULL;
  227.     _err = SndPauseFilePlay(_self->ob_itself);
  228.     if (_err != noErr) return PyMac_Error(_err);
  229.     Py_INCREF(Py_None);
  230.     _res = Py_None;
  231.     return _res;
  232. }
  233.  
  234. static PyObject *SndCh_SndStopFilePlay(_self, _args)
  235.     SndChannelObject *_self;
  236.     PyObject *_args;
  237. {
  238.     PyObject *_res = NULL;
  239.     OSErr _err;
  240.     Boolean quietNow;
  241.     if (!PyArg_ParseTuple(_args, "b",
  242.                           &quietNow))
  243.         return NULL;
  244.     _err = SndStopFilePlay(_self->ob_itself,
  245.                            quietNow);
  246.     if (_err != noErr) return PyMac_Error(_err);
  247.     Py_INCREF(Py_None);
  248.     _res = Py_None;
  249.     return _res;
  250. }
  251.  
  252. static PyObject *SndCh_SndChannelStatus(_self, _args)
  253.     SndChannelObject *_self;
  254.     PyObject *_args;
  255. {
  256.     PyObject *_res = NULL;
  257.     OSErr _err;
  258.     short theLength;
  259.     SCStatus theStatus__out__;
  260.     if (!PyArg_ParseTuple(_args, "h",
  261.                           &theLength))
  262.         return NULL;
  263.     _err = SndChannelStatus(_self->ob_itself,
  264.                             theLength,
  265.                             &theStatus__out__);
  266.     if (_err != noErr) return PyMac_Error(_err);
  267.     _res = Py_BuildValue("s#",
  268.                          (char *)&theStatus__out__, (int)sizeof(SCStatus));
  269.  theStatus__error__: ;
  270.     return _res;
  271. }
  272.  
  273. static PyMethodDef SndCh_methods[] = {
  274.     {"SndDoCommand", (PyCFunction)SndCh_SndDoCommand, 1,
  275.      "(SndCommand cmd, Boolean noWait) -> None"},
  276.     {"SndDoImmediate", (PyCFunction)SndCh_SndDoImmediate, 1,
  277.      "(SndCommand cmd) -> None"},
  278.     {"SndPlay", (PyCFunction)SndCh_SndPlay, 1,
  279.      "(SndListHandle sndHdl, Boolean async) -> None"},
  280.     {"SndStartFilePlay", (PyCFunction)SndCh_SndStartFilePlay, 1,
  281.      "(short fRefNum, short resNum, long bufferSize, Boolean async) -> None"},
  282.     {"SndPauseFilePlay", (PyCFunction)SndCh_SndPauseFilePlay, 1,
  283.      "() -> None"},
  284.     {"SndStopFilePlay", (PyCFunction)SndCh_SndStopFilePlay, 1,
  285.      "(Boolean quietNow) -> None"},
  286.     {"SndChannelStatus", (PyCFunction)SndCh_SndChannelStatus, 1,
  287.      "(short theLength) -> (SCStatus theStatus)"},
  288.     {NULL, NULL, 0}
  289. };
  290.  
  291. static PyMethodChain SndCh_chain = { SndCh_methods, NULL };
  292.  
  293. static PyObject *SndCh_getattr(self, name)
  294.     SndChannelObject *self;
  295.     char *name;
  296. {
  297.     return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name);
  298. }
  299.  
  300. #define SndCh_setattr NULL
  301.  
  302. staticforward PyTypeObject SndChannel_Type = {
  303.     PyObject_HEAD_INIT(&PyType_Type)
  304.     0, /*ob_size*/
  305.     "SndChannel", /*tp_name*/
  306.     sizeof(SndChannelObject), /*tp_basicsize*/
  307.     0, /*tp_itemsize*/
  308.     /* methods */
  309.     (destructor) SndCh_dealloc, /*tp_dealloc*/
  310.     0, /*tp_print*/
  311.     (getattrfunc) SndCh_getattr, /*tp_getattr*/
  312.     (setattrfunc) SndCh_setattr, /*tp_setattr*/
  313. };
  314.  
  315. /* ------------------- End object type SndChannel ------------------- */
  316.  
  317.  
  318. static PyObject *Snd_SndNewChannel(_self, _args)
  319.     PyObject *_self;
  320.     PyObject *_args;
  321. {
  322.     PyObject *_res = NULL;
  323.     OSErr _err;
  324.     SndChannelPtr chan = 0;
  325.     short synth;
  326.     long init;
  327.     PyObject* userRoutine;
  328.     if (!PyArg_ParseTuple(_args, "hlO",
  329.                           &synth,
  330.                           &init,
  331.                           &userRoutine))
  332.         return NULL;
  333.     if (userRoutine != Py_None && !PyCallable_Check(userRoutine))
  334.     {
  335.         PyErr_SetString(PyExc_TypeError, "callback must be callable");
  336.         goto userRoutine__error__;
  337.     }
  338.     _err = SndNewChannel(&chan,
  339.                          synth,
  340.                          init,
  341.                          NewSndCallBackProc(SndCh_UserRoutine));
  342.     if (_err != noErr) return PyMac_Error(_err);
  343.     _res = Py_BuildValue("O&",
  344.                          SndCh_New, chan);
  345.     if (_res != NULL && userRoutine != Py_None)
  346.     {
  347.         SndChannelObject *p = (SndChannelObject *)_res;
  348.         p->ob_itself->userInfo = (long)p;
  349.         Py_INCREF(userRoutine);
  350.         p->ob_callback = userRoutine;
  351.     }
  352.  userRoutine__error__: ;
  353.     return _res;
  354. }
  355.  
  356. static PyObject *Snd_SndControl(_self, _args)
  357.     PyObject *_self;
  358.     PyObject *_args;
  359. {
  360.     PyObject *_res = NULL;
  361.     OSErr _err;
  362.     short id;
  363.     SndCommand cmd;
  364.     if (!PyArg_ParseTuple(_args, "h",
  365.                           &id))
  366.         return NULL;
  367.     _err = SndControl(id,
  368.                       &cmd);
  369.     if (_err != noErr) return PyMac_Error(_err);
  370.     _res = Py_BuildValue("O&",
  371.                          SndCmd_New, &cmd);
  372.     return _res;
  373. }
  374.  
  375. static PyObject *Snd_SndSoundManagerVersion(_self, _args)
  376.     PyObject *_self;
  377.     PyObject *_args;
  378. {
  379.     PyObject *_res = NULL;
  380.     NumVersion _rv;
  381.     if (!PyArg_ParseTuple(_args, ""))
  382.         return NULL;
  383.     _rv = SndSoundManagerVersion();
  384.     _res = Py_BuildValue("O&",
  385.                          PyMac_BuildNumVersion, _rv);
  386.     return _res;
  387. }
  388.  
  389. static PyObject *Snd_SndManagerStatus(_self, _args)
  390.     PyObject *_self;
  391.     PyObject *_args;
  392. {
  393.     PyObject *_res = NULL;
  394.     OSErr _err;
  395.     short theLength;
  396.     SMStatus theStatus__out__;
  397.     if (!PyArg_ParseTuple(_args, "h",
  398.                           &theLength))
  399.         return NULL;
  400.     _err = SndManagerStatus(theLength,
  401.                             &theStatus__out__);
  402.     if (_err != noErr) return PyMac_Error(_err);
  403.     _res = Py_BuildValue("s#",
  404.                          (char *)&theStatus__out__, (int)sizeof(SMStatus));
  405.  theStatus__error__: ;
  406.     return _res;
  407. }
  408.  
  409. static PyObject *Snd_SndGetSysBeepState(_self, _args)
  410.     PyObject *_self;
  411.     PyObject *_args;
  412. {
  413.     PyObject *_res = NULL;
  414.     short sysBeepState;
  415.     if (!PyArg_ParseTuple(_args, ""))
  416.         return NULL;
  417.     SndGetSysBeepState(&sysBeepState);
  418.     _res = Py_BuildValue("h",
  419.                          sysBeepState);
  420.     return _res;
  421. }
  422.  
  423. static PyObject *Snd_SndSetSysBeepState(_self, _args)
  424.     PyObject *_self;
  425.     PyObject *_args;
  426. {
  427.     PyObject *_res = NULL;
  428.     OSErr _err;
  429.     short sysBeepState;
  430.     if (!PyArg_ParseTuple(_args, "h",
  431.                           &sysBeepState))
  432.         return NULL;
  433.     _err = SndSetSysBeepState(sysBeepState);
  434.     if (_err != noErr) return PyMac_Error(_err);
  435.     Py_INCREF(Py_None);
  436.     _res = Py_None;
  437.     return _res;
  438. }
  439.  
  440. static PyObject *Snd_MACEVersion(_self, _args)
  441.     PyObject *_self;
  442.     PyObject *_args;
  443. {
  444.     PyObject *_res = NULL;
  445.     NumVersion _rv;
  446.     if (!PyArg_ParseTuple(_args, ""))
  447.         return NULL;
  448.     _rv = MACEVersion();
  449.     _res = Py_BuildValue("O&",
  450.                          PyMac_BuildNumVersion, _rv);
  451.     return _res;
  452. }
  453.  
  454. static PyObject *Snd_Comp3to1(_self, _args)
  455.     PyObject *_self;
  456.     PyObject *_args;
  457. {
  458.     PyObject *_res = NULL;
  459.     char *buffer__in__;
  460.     char *buffer__out__;
  461.     long buffer__len__;
  462.     int buffer__in_len__;
  463.     StateBlock *state__in__;
  464.     StateBlock state__out__;
  465.     int state__in_len__;
  466.     unsigned long numChannels;
  467.     unsigned long whichChannel;
  468.     if (!PyArg_ParseTuple(_args, "s#s#ll",
  469.                           &buffer__in__, &buffer__in_len__,
  470.                           (char **)&state__in__, &state__in_len__,
  471.                           &numChannels,
  472.                           &whichChannel))
  473.         return NULL;
  474.     if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
  475.     {
  476.         PyErr_NoMemory();
  477.         goto buffer__error__;
  478.     }
  479.     buffer__len__ = buffer__in_len__;
  480.     if (state__in_len__ != sizeof(StateBlock))
  481.     {
  482.         PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
  483.         goto state__error__;
  484.     }
  485.     Comp3to1(buffer__in__, buffer__out__, (long)buffer__len__,
  486.              state__in__, &state__out__,
  487.              numChannels,
  488.              whichChannel);
  489.     _res = Py_BuildValue("s#s#",
  490.                          buffer__out__, (int)buffer__len__,
  491.                          (char *)&state__out__, (int)sizeof(StateBlock));
  492.  state__error__: ;
  493.     free(buffer__out__);
  494.  buffer__error__: ;
  495.     return _res;
  496. }
  497.  
  498. static PyObject *Snd_Exp1to3(_self, _args)
  499.     PyObject *_self;
  500.     PyObject *_args;
  501. {
  502.     PyObject *_res = NULL;
  503.     char *buffer__in__;
  504.     char *buffer__out__;
  505.     long buffer__len__;
  506.     int buffer__in_len__;
  507.     StateBlock *state__in__;
  508.     StateBlock state__out__;
  509.     int state__in_len__;
  510.     unsigned long numChannels;
  511.     unsigned long whichChannel;
  512.     if (!PyArg_ParseTuple(_args, "s#s#ll",
  513.                           &buffer__in__, &buffer__in_len__,
  514.                           (char **)&state__in__, &state__in_len__,
  515.                           &numChannels,
  516.                           &whichChannel))
  517.         return NULL;
  518.     if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
  519.     {
  520.         PyErr_NoMemory();
  521.         goto buffer__error__;
  522.     }
  523.     buffer__len__ = buffer__in_len__;
  524.     if (state__in_len__ != sizeof(StateBlock))
  525.     {
  526.         PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
  527.         goto state__error__;
  528.     }
  529.     Exp1to3(buffer__in__, buffer__out__, (long)buffer__len__,
  530.             state__in__, &state__out__,
  531.             numChannels,
  532.             whichChannel);
  533.     _res = Py_BuildValue("s#s#",
  534.                          buffer__out__, (int)buffer__len__,
  535.                          (char *)&state__out__, (int)sizeof(StateBlock));
  536.  state__error__: ;
  537.     free(buffer__out__);
  538.  buffer__error__: ;
  539.     return _res;
  540. }
  541.  
  542. static PyObject *Snd_Comp6to1(_self, _args)
  543.     PyObject *_self;
  544.     PyObject *_args;
  545. {
  546.     PyObject *_res = NULL;
  547.     char *buffer__in__;
  548.     char *buffer__out__;
  549.     long buffer__len__;
  550.     int buffer__in_len__;
  551.     StateBlock *state__in__;
  552.     StateBlock state__out__;
  553.     int state__in_len__;
  554.     unsigned long numChannels;
  555.     unsigned long whichChannel;
  556.     if (!PyArg_ParseTuple(_args, "s#s#ll",
  557.                           &buffer__in__, &buffer__in_len__,
  558.                           (char **)&state__in__, &state__in_len__,
  559.                           &numChannels,
  560.                           &whichChannel))
  561.         return NULL;
  562.     if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
  563.     {
  564.         PyErr_NoMemory();
  565.         goto buffer__error__;
  566.     }
  567.     buffer__len__ = buffer__in_len__;
  568.     if (state__in_len__ != sizeof(StateBlock))
  569.     {
  570.         PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
  571.         goto state__error__;
  572.     }
  573.     Comp6to1(buffer__in__, buffer__out__, (long)buffer__len__,
  574.              state__in__, &state__out__,
  575.              numChannels,
  576.              whichChannel);
  577.     _res = Py_BuildValue("s#s#",
  578.                          buffer__out__, (int)buffer__len__,
  579.                          (char *)&state__out__, (int)sizeof(StateBlock));
  580.  state__error__: ;
  581.     free(buffer__out__);
  582.  buffer__error__: ;
  583.     return _res;
  584. }
  585.  
  586. static PyObject *Snd_Exp1to6(_self, _args)
  587.     PyObject *_self;
  588.     PyObject *_args;
  589. {
  590.     PyObject *_res = NULL;
  591.     char *buffer__in__;
  592.     char *buffer__out__;
  593.     long buffer__len__;
  594.     int buffer__in_len__;
  595.     StateBlock *state__in__;
  596.     StateBlock state__out__;
  597.     int state__in_len__;
  598.     unsigned long numChannels;
  599.     unsigned long whichChannel;
  600.     if (!PyArg_ParseTuple(_args, "s#s#ll",
  601.                           &buffer__in__, &buffer__in_len__,
  602.                           (char **)&state__in__, &state__in_len__,
  603.                           &numChannels,
  604.                           &whichChannel))
  605.         return NULL;
  606.     if ((buffer__out__ = malloc(buffer__in_len__)) == NULL)
  607.     {
  608.         PyErr_NoMemory();
  609.         goto buffer__error__;
  610.     }
  611.     buffer__len__ = buffer__in_len__;
  612.     if (state__in_len__ != sizeof(StateBlock))
  613.     {
  614.         PyErr_SetString(PyExc_TypeError, "buffer length should be sizeof(StateBlock)");
  615.         goto state__error__;
  616.     }
  617.     Exp1to6(buffer__in__, buffer__out__, (long)buffer__len__,
  618.             state__in__, &state__out__,
  619.             numChannels,
  620.             whichChannel);
  621.     _res = Py_BuildValue("s#s#",
  622.                          buffer__out__, (int)buffer__len__,
  623.                          (char *)&state__out__, (int)sizeof(StateBlock));
  624.  state__error__: ;
  625.     free(buffer__out__);
  626.  buffer__error__: ;
  627.     return _res;
  628. }
  629.  
  630. static PyObject *Snd_GetSysBeepVolume(_self, _args)
  631.     PyObject *_self;
  632.     PyObject *_args;
  633. {
  634.     PyObject *_res = NULL;
  635.     OSErr _err;
  636.     long level;
  637.     if (!PyArg_ParseTuple(_args, ""))
  638.         return NULL;
  639.     _err = GetSysBeepVolume(&level);
  640.     if (_err != noErr) return PyMac_Error(_err);
  641.     _res = Py_BuildValue("l",
  642.                          level);
  643.     return _res;
  644. }
  645.  
  646. static PyObject *Snd_SetSysBeepVolume(_self, _args)
  647.     PyObject *_self;
  648.     PyObject *_args;
  649. {
  650.     PyObject *_res = NULL;
  651.     OSErr _err;
  652.     long level;
  653.     if (!PyArg_ParseTuple(_args, "l",
  654.                           &level))
  655.         return NULL;
  656.     _err = SetSysBeepVolume(level);
  657.     if (_err != noErr) return PyMac_Error(_err);
  658.     Py_INCREF(Py_None);
  659.     _res = Py_None;
  660.     return _res;
  661. }
  662.  
  663. static PyObject *Snd_GetDefaultOutputVolume(_self, _args)
  664.     PyObject *_self;
  665.     PyObject *_args;
  666. {
  667.     PyObject *_res = NULL;
  668.     OSErr _err;
  669.     long level;
  670.     if (!PyArg_ParseTuple(_args, ""))
  671.         return NULL;
  672.     _err = GetDefaultOutputVolume(&level);
  673.     if (_err != noErr) return PyMac_Error(_err);
  674.     _res = Py_BuildValue("l",
  675.                          level);
  676.     return _res;
  677. }
  678.  
  679. static PyObject *Snd_SetDefaultOutputVolume(_self, _args)
  680.     PyObject *_self;
  681.     PyObject *_args;
  682. {
  683.     PyObject *_res = NULL;
  684.     OSErr _err;
  685.     long level;
  686.     if (!PyArg_ParseTuple(_args, "l",
  687.                           &level))
  688.         return NULL;
  689.     _err = SetDefaultOutputVolume(level);
  690.     if (_err != noErr) return PyMac_Error(_err);
  691.     Py_INCREF(Py_None);
  692.     _res = Py_None;
  693.     return _res;
  694. }
  695.  
  696. static PyObject *Snd_GetSoundHeaderOffset(_self, _args)
  697.     PyObject *_self;
  698.     PyObject *_args;
  699. {
  700.     PyObject *_res = NULL;
  701.     OSErr _err;
  702.     SndListHandle sndHandle;
  703.     long offset;
  704.     if (!PyArg_ParseTuple(_args, "O&",
  705.                           ResObj_Convert, &sndHandle))
  706.         return NULL;
  707.     _err = GetSoundHeaderOffset(sndHandle,
  708.                                 &offset);
  709.     if (_err != noErr) return PyMac_Error(_err);
  710.     _res = Py_BuildValue("l",
  711.                          offset);
  712.     return _res;
  713. }
  714.  
  715. static PyMethodDef Snd_methods[] = {
  716.     {"SndNewChannel", (PyCFunction)Snd_SndNewChannel, 1,
  717.      "(short synth, long init, PyObject* userRoutine) -> (SndChannelPtr chan)"},
  718.     {"SndControl", (PyCFunction)Snd_SndControl, 1,
  719.      "(short id) -> (SndCommand cmd)"},
  720.     {"SndSoundManagerVersion", (PyCFunction)Snd_SndSoundManagerVersion, 1,
  721.      "() -> (NumVersion _rv)"},
  722.     {"SndManagerStatus", (PyCFunction)Snd_SndManagerStatus, 1,
  723.      "(short theLength) -> (SMStatus theStatus)"},
  724.     {"SndGetSysBeepState", (PyCFunction)Snd_SndGetSysBeepState, 1,
  725.      "() -> (short sysBeepState)"},
  726.     {"SndSetSysBeepState", (PyCFunction)Snd_SndSetSysBeepState, 1,
  727.      "(short sysBeepState) -> None"},
  728.     {"MACEVersion", (PyCFunction)Snd_MACEVersion, 1,
  729.      "() -> (NumVersion _rv)"},
  730.     {"Comp3to1", (PyCFunction)Snd_Comp3to1, 1,
  731.      "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
  732.     {"Exp1to3", (PyCFunction)Snd_Exp1to3, 1,
  733.      "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
  734.     {"Comp6to1", (PyCFunction)Snd_Comp6to1, 1,
  735.      "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
  736.     {"Exp1to6", (PyCFunction)Snd_Exp1to6, 1,
  737.      "(Buffer buffer, StateBlock state, unsigned long numChannels, unsigned long whichChannel) -> (Buffer buffer, StateBlock state)"},
  738.     {"GetSysBeepVolume", (PyCFunction)Snd_GetSysBeepVolume, 1,
  739.      "() -> (long level)"},
  740.     {"SetSysBeepVolume", (PyCFunction)Snd_SetSysBeepVolume, 1,
  741.      "(long level) -> None"},
  742.     {"GetDefaultOutputVolume", (PyCFunction)Snd_GetDefaultOutputVolume, 1,
  743.      "() -> (long level)"},
  744.     {"SetDefaultOutputVolume", (PyCFunction)Snd_SetDefaultOutputVolume, 1,
  745.      "(long level) -> None"},
  746.     {"GetSoundHeaderOffset", (PyCFunction)Snd_GetSoundHeaderOffset, 1,
  747.      "(SndListHandle sndHandle) -> (long offset)"},
  748.     {NULL, NULL, 0}
  749. };
  750.  
  751.  
  752.  
  753. /* Routine passed to Py_AddPendingCall -- call the Python callback */
  754. static int
  755. SndCh_CallCallBack(arg)
  756.     void *arg;
  757. {
  758.     SndChannelObject *p = (SndChannelObject *)arg;
  759.     PyObject *args;
  760.     PyObject *res;
  761.     args = Py_BuildValue("(O(hhl))",
  762.                          p, p->ob_cmd.cmd, p->ob_cmd.param1, p->ob_cmd.param2);
  763.     res = PyEval_CallObject(p->ob_callback, args);
  764.     Py_DECREF(args);
  765.     if (res == NULL)
  766.         return -1;
  767.     Py_DECREF(res);
  768.     return 0;
  769. }
  770.  
  771. /* Routine passed to NewSndChannel -- schedule a call to SndCh_CallCallBack */
  772. static pascal void
  773. SndCh_UserRoutine(SndChannelPtr chan, SndCommand *cmd)
  774. {
  775.     SndChannelObject *p = (SndChannelObject *)(chan->userInfo);
  776.     if (p->ob_callback != NULL) {
  777.         long A5 = SetA5(p->ob_A5);
  778.         p->ob_cmd = *cmd;
  779.         Py_AddPendingCall(SndCh_CallCallBack, (void *)p);
  780.         SetA5(A5);
  781.     }
  782. }
  783.  
  784.  
  785. void initSnd()
  786. {
  787.     PyObject *m;
  788.     PyObject *d;
  789.  
  790.  
  791.  
  792.  
  793.  
  794.     m = Py_InitModule("Snd", Snd_methods);
  795.     d = PyModule_GetDict(m);
  796.     Snd_Error = PyMac_GetOSErrException();
  797.     if (Snd_Error == NULL ||
  798.         PyDict_SetItemString(d, "Error", Snd_Error) != 0)
  799.         Py_FatalError("can't initialize Snd.Error");
  800. }
  801.  
  802. /* ========================= End module Snd ========================= */
  803.  
  804.